package com.tarena.lbs.marketing.web.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.marketing.web.mapper.CouponMapper;
import com.tarena.lbs.pojo.marketing.po.CouponPO;
import com.tarena.lbs.pojo.marketing.query.CouponQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CouponRepository {
    @Autowired
    private CouponMapper couponMapper;

    public PageInfo<CouponPO> getCouponsByPage(CouponQuery couponQuery) {
        //1.查询参数 couponType 优惠券类型 couponName 名称 status 状态 businessId所属商家
        QueryWrapper<CouponPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_id",couponQuery.getBusinessId());
        //2.开启分页
        PageHelper.startPage(couponQuery.getPageNo(),couponQuery.getPageSize());
        List<CouponPO> pos = couponMapper.selectList(queryWrapper);
        return new PageInfo<>(pos);
    }

    public void saveCoupon(CouponPO couponPO) {
        couponMapper.insert(couponPO);
    }

    public CouponPO getCouponById(Integer rewardCouponId) {
        return couponMapper.selectById(rewardCouponId);
    }
}
